<?php

/**
 * 内容管理
 * File Name：ContentController.php
 * File Encoding：UTF-8
 * File New Time：2014-10-14 17:29:05
 * Author：水平凡
 * Mailbox：admin@abc3210.com
 */
class ContentController extends AdminBase {

    //信息列表
    public function actionList() {
        //搜索
        if (IS_POST) {
            foreach ($_POST as $k => $v) {
                if ($v == '') {
                    unset($_POST[$k]);
                }
            }
            $this->redirect(AdminBase::U('list', $_POST));
            exit;
        }
        $model = ContentArticlesModel::model();
        $where = array(
            'order' => 'id desc'
        );
        //搜索处理
        $keyword = Yii::app()->request->getParam('keyword');
        if (!empty($keyword)) {
            $type = Yii::app()->request->getParam('type');
            switch ($type) {
                case 'title':
                    $where['title'] = array('LIKE', "%{$keyword}%");
                    break;
                default:
                    $where['title'] = array('LIKE', "%{$keyword}%");
                    break;
            }
            $this->assign('type', $type);
            $this->assign('keyword', $keyword);
        }
        $limit = 20;
        $this->basePage($model, $where, $limit);
        $this->render();
    }

    //添加
    public function actionAdd() {
        $model = ContentArticlesModel::model();
        $catid = (int) Yii::app()->request->getParam('catid');
        $this->assign('catid', $catid);
        $this->baseAdd($model, 'list');
    }

    //编辑
    public function actionEdit() {
        $model = ContentArticlesModel::model();
        $this->baseEdit($model, 'list');
    }

    //删除
    public function actionDelete() {
        $model = ContentArticlesModel::model();
        $this->baseDelete($model, 'list');
    }

}
